import 'package:flutter_blue_plus/flutter_blue_plus.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

class BleStatusMonitor {
  // 检查蓝牙是否开启
  static Future<bool> isBluetoothOn() async {
    return await FlutterBluePlus.isOn;
  }

  // 监听蓝牙状态变化
  static Stream<BluetoothAdapterState> get bluetoothStateStream {
    return FlutterBluePlus.adapterState;
  }

  // 开启蓝牙 (Android only)
  static Future<void> turnOnBluetooth() async {
    if (!await isBluetoothOn()) {
      await FlutterBluePlus.turnOn();
    }
  }
}

final bluetoothStatusProvider = StreamProvider<BluetoothAdapterState>((ref) {
  return FlutterBluePlus.adapterState; // 实时监听蓝牙开关
});
